/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) radix(10) lradix(10) 
// Source File Name:   InvoiceSourceDMO.java

package nc.bs.scm.sourcebill;

import java.sql.*;
import java.util.Vector;
import javax.naming.NamingException;
import nc.bs.pub.SystemException;
import nc.vo.scm.sourcebill.LightBillVO;

// Referenced classes of package nc.bs.scm.sourcebill:
//            DefaultSourceDMO

public class InvoiceSourceDMO extends DefaultSourceDMO
{

    public InvoiceSourceDMO()
        throws NamingException, SystemException
    {
    }

    public InvoiceSourceDMO(String dbName)
        throws NamingException, SystemException
    {
        super(dbName);
    }

    public LightBillVO[] getForwardBills(String curBillType, String curBillID, String forwardBillType)
    {
        Connection con;
        PreparedStatement stmt;
        Vector v;
        String sql;
        beforeCallMethod("nc.bs.scm.sourcebill.SourceBillDMO", "getForwardBills", new Object[] {
            curBillType, curBillID, forwardBillType
        });
        con = null;
        stmt = null;
        ResultSet rs = null;
        v = new Vector();
        sql = null;
        if("27".equals(forwardBillType))
            sql = "SELECT DISTINCT po_settlebill.csettlebillid, po_settlebill.vsettlebillcode FROM po_settlebill INNER JOIN po_settlebill_b ON po_settlebill.csettlebillid = po_settlebill_b.csettlebillid WHERE (po_settlebill_b.cinvoiceid = ? and po_settlebill_b.dr = 0 and po_settlebill.dr = 0)";
        else if("27".equals(forwardBillType))
            sql = "select distinct arap_djfb.vouchid, arap_djfb.djbh from arap_djfb where arap_djfb.dr = 0 and arap_djfb.ddlx = ?";
        else if("I9".equals(forwardBillType))
        	sql = "select distinct h.cbillid,h.vbillcode from ia_bill h,ia_bill_b b where h.cbillid = b.cbillid and h.dr = 0 and b.dr = 0 and b.csourcebillid = ?";
        
        try {
        	con = getConnection();
        	stmt = con.prepareStatement(sql);
        	stmt.setString(1, curBillID);
        	rs = stmt.executeQuery();
        	do
        	{
        		if(!rs.next())
        			break;
        		String id = rs.getString(1);
        		String code = rs.getString(2);
        		if(id != null)
        		{
        			LightBillVO svo = new LightBillVO();
        			svo.setID(id);
        			svo.setCode(code);
        			svo.setType(forwardBillType);
        			v.add(svo);
        		}
        	} while(true);
		} catch (Exception e) {
		}
		finally
		{
			try
			{
				if(stmt != null)
					stmt.close();
			}
			// Misplaced declaration of an exception variable
			catch(Exception e) { }
			try
			{
				if(con != null)
					con.close();
			}
			// Misplaced declaration of an exception variable
			catch(Exception e) { }
			try
			{
				if(stmt != null)
					stmt.close();
			}
			// Misplaced declaration of an exception variable
			catch(Exception e) { }
			try
			{
				if(con != null)
					con.close();
			}
			// Misplaced declaration of an exception variable
			catch(Exception e) { }
		}
        
        afterCallMethod("nc.bs.scm.sourcebill.SourceBillDMO", "getForwardBills", new Object[] {
            curBillType, curBillID, forwardBillType
        });
        LightBillVO svos[] = null;
        if(v.size() > 0)
        {
            svos = new LightBillVO[v.size()];
            v.copyInto(svos);
        }
        return svos;
    }
}
